#include "ICritvsLengthAlgo.h"

#include "ICritAlgo.h"
#include "ICritvsLengthSave.h"
#include "InitSave.h"
#include "FinalPosition.h"

#include <iostream>

ICritvsLengthAlgo::ICritvsLengthAlgo()
{

}

ICritvsLengthAlgo::~ICritvsLengthAlgo()
{

}

int ICritvsLengthAlgo::solve(Clock clock,Output output,Pulse *field,Pulse *current,MultiLayer multiLayer,NewParameters params)
{
  multiLayer[multiLayer.getSolveLayer()].setSwitchedMag(FinalPosition(clock,output,field,current,multiLayer,params));
  for(current->setLength(1E-10);current->getLength()<=1E-9;current->setLength(current->getLength()+1E-10))
    {
      double icrit=ICritAlgo().solve(clock,output,field,current,multiLayer,params);
      std::cout<<"I="<<icrit<<std::endl;
      std::cout<<"t="<<current->getLength()<<std::endl;
      output.setSave(true);
      ICritvsLengthSave().save(output,current->getLength(),icrit);
      output.setSave(false); 
    }
  for(current->setLength(2E-9);current->getLength()<=15E-9;current->setLength(current->getLength()+0.5E-9))
    {
      double icrit=ICritAlgo().solve(clock,output,field,current,multiLayer,params);
      std::cout<<"I="<<icrit<<std::endl;
      std::cout<<"t="<<current->getLength()<<std::endl;
      output.setSave(true);
      ICritvsLengthSave().save(output,current->getLength(),icrit);
      output.setSave(false);
      }
  return 0;
}
